package cn.xinzhi.servlet;

import cn.xinzhi.service.impl.PageServiceImpl;
import cn.xinzhi.until.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ShowPageServletServlet")
public class ShowPageServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();

            String index = request.getParameter("index");
            String pageSize = request.getParameter("ps");
            PageServiceImpl psi = new PageServiceImpl();
            PageUtil pu = psi.showPage(index,pageSize);
            request.setAttribute("pu",pu);
            request.getSession().setAttribute("nowPage",pu.getUis());
            request.getRequestDispatcher("show.jsp").forward(request,response);

            out.close();
            out.flush();
        }

}
